package com.ruoyi.system.service.impl;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ruoyi.common.core.page.PlatTableDataInfo;
import com.ruoyi.common.exception.BusinessException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.system.domain.*;
import com.ruoyi.system.domain.vo.*;
import com.ruoyi.system.domain.vo.answer.AnswerSelectVO;
import com.ruoyi.system.domain.vo.answer.ReqCommonVO;
import com.ruoyi.system.mapper.*;
import com.ruoyi.system.service.IPlatLessonService;
import com.ruoyi.system.service.IPlatUserService;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 课程管理
 */
@Service
public class PlatLessonServiceImpl extends PlatCommonServiceImpl implements IPlatLessonService {

    @Autowired
    private PlatMajorMapper platMajorMapper;
    @Autowired
    private PlatCollegeMapper platCollegeMapper;
    @Autowired
    private IPlatUserService platUserService;
    @Autowired
    private PlatUserMapper platUserMapper;
    @Autowired
    private PlatLessonMapper platLessonMapper;
    @Autowired
    private PlatLessonChapterTypeMapper platLessonChapterTypeMapper;
    @Autowired
    private PlatLessonScheduleMapper platLessonScheduleMapper;
    @Autowired
    private PlatClassMapper platClassMapper;
    @Autowired
    private PlatLessonStudentMapper platLessonStudentMapper;
    @Autowired
    private PlatLessonTypeMapper platLessonTypeMapper;
    @Autowired
    private PlatLessonStudentAnswerMapper PlatLessonStudentAnswerMapper;
    @Autowired
    private PlatLessonSonMapper platLessonSonMapper;
    @Autowired
    private PlatLessonLabelMapper platLessonLabelMapper;

    private static final Logger log = LoggerFactory.getLogger(PlatLessonServiceImpl.class);

    @Override
    public void addLesson(PlatLesson platLesson) {
        //校验名称是否重复
        PlatLessonExample example = new PlatLessonExample();
        PlatLessonExample.Criteria criteria = example.createCriteria();
        criteria.andNameEqualTo(platLesson.getName());
        List<PlatLesson> list = platLessonMapper.selectByExample(example);
        if (platLesson.getId() != null && list.size() > 0 && !String.valueOf(list.get(0).getId()).equals(String.valueOf(platLesson.getId()))) {
            throw new BusinessException("课程名称已存在!");
        } else if (platLesson.getId() == null && list.size() > 0) {
            throw new BusinessException("课程名称已存在!");
        }

        if (!StringUtils.isEmpty(platLesson.getTeachers())) {
            String[] arrays = platLesson.getTeachers().split(DOUHAO);
            StringBuffer stringBuffer = new StringBuffer();
            stringBuffer.append(IDENTIFICATION);
            for (String teacherId : arrays) {
                stringBuffer.append(teacherId);
                stringBuffer.append(IDENTIFICATION);
            }
            platLesson.setTeachers(stringBuffer.toString());
        }

        if (!StringUtils.isEmpty(platLesson.getMajors())) {
            String[] arrays = platLesson.getMajors().split(DOUHAO);
            StringBuffer stringBuffer = new StringBuffer();
            stringBuffer.append(IDENTIFICATION);
            for (String majorId : arrays) {
                stringBuffer.append(majorId);
                stringBuffer.append(IDENTIFICATION);
            }
            platLesson.setMajors(stringBuffer.toString());
        }

        if(platLesson.getId() == null && !StringUtils.isEmpty(platLesson.getTypeId())){
            platLesson.setTypeId(LIKE + IDENTIFICATION + platLesson.getTypeId() + IDENTIFICATION + LIKE);
        }

        if (platLesson.getId() != null) {
            platLesson.setTypeId(null);
            platLesson.setUpdateTime(new Date());
            platLessonMapper.updateByPrimaryKeySelective(platLesson);
            return;
        }
        platLesson.setCreateTime(new Date());
        platLessonMapper.insert(platLesson);
    }

    private String getPlatLessonTypeName(PlatLesson platLesson, String typeId) {
        if (platLesson != null && !StringUtils.isEmpty(platLesson.getTypeId())) {
            PlatLessonType platLessonType = platLessonTypeMapper.selectByPrimaryKey(Long.parseLong(platLesson.getTypeId()));
            return platLessonType == null ? "" : platLessonType.getName();
        }

        if (typeId == null) {
            return "";
        }
        if (!typeId.contains(IDENTIFICATION)) {
            PlatLessonType platLessonType = platLessonTypeMapper.selectByPrimaryKey(Long.parseLong(typeId));
            return platLessonType == null ? "" : platLessonType.getName();
        } else {
            String name = null;
            String[] arrays = typeId.split(IDENTIFICATION);
            for (String id : arrays) {
                if (StringUtils.isEmpty(id)) {
                    continue;
                }
                PlatLessonType platLessonType = platLessonTypeMapper.selectByPrimaryKey(Long.parseLong(id));
                if (platLessonType != null) {
                    if (name == null) {
                        name = platLessonType.getName();
                    } else {
                        name = name + "," + platLessonType.getName();
                    }
                }
            }
            return name;
        }
    }

    @Override
    public List<PlatLesson> lessonList(PlatLesson platLesson,HttpServletRequest request) {
        PlatLessonExample platLessonExample = new PlatLessonExample();
        PlatLessonExample.Criteria criteria = platLessonExample.createCriteria();
        if (!StringUtils.isEmpty(platLesson.getName())) {
            criteria.andNameLike(LIKE + platLesson.getName() + LIKE);
        }

        if (!StringUtils.isEmpty(platLesson.getLabelId())) {
            criteria.andLabelIdLike(LIKE  + IDENTIFICATION +  platLesson.getLabelId()  + IDENTIFICATION +  LIKE);
        }

        if (platLesson.getTypeId() != null) {
            criteria.andTypeIdLike(LIKE + IDENTIFICATION + platLesson.getTypeId() + IDENTIFICATION + LIKE);
        } else {
            //你的意思应该是 点课程列表那里 先不出来全部的课程列表 先选个模块 再出来列表.现在是点课程列表 会出来全部的课程 你再根据条件筛查一下才可以
            criteria.andTypeIdEqualTo(IDENTIFICATION);
        }
        List<PlatLesson> list = platLessonMapper.selectByExample(platLessonExample);

        for (PlatLesson platLessonPO : list) {
            platLessonPO.setTypeName(getPlatLessonTypeName(platLesson, platLessonPO.getTypeId()));

            PlatCollege platCollege = platCollegeMapper.selectByPrimaryKey(platLessonPO.getCollegeId());
            if (platCollege != null) {
                platLessonPO.setCollegeName(platCollege.getName());
            }

            String teacher = "";
            if (!StringUtils.isEmpty(platLessonPO.getTeachers())) {
                String[] arrays = platLessonPO.getTeachers().split(IDENTIFICATION);
                for (String teacherId : arrays) {
                    try {
                        if (StringUtils.isEmpty(teacherId)) {
                            continue;
                        }
                        PlatUser platUser = platUserMapper.selectByPrimaryKey(Long.parseLong(teacherId));
                        if (platUser != null) {
                            if (StringUtils.isEmpty(teacher)) {
                                teacher = platUser.getNickName();
                            } else {
                                teacher += DOUHAO + platUser.getNickName();
                            }
                        }
                    } catch (Exception e) {
                        error("查询授课教师失败", e);
                    }
                }

            }
            platLessonPO.setTeachers(teacher);

            String majors = "";
            if (!StringUtils.isEmpty(platLessonPO.getMajors())) {
                String[] arrays = platLessonPO.getMajors().split(IDENTIFICATION);
                for (String majorId : arrays) {
                    try {
                        if (StringUtils.isEmpty(majorId)) {
                            continue;
                        }

                        PlatMajor platMajor = platMajorMapper.selectByPrimaryKey(Long.parseLong(majorId));
                        if (platMajor != null) {
                            if (StringUtils.isEmpty(majors)) {
                                majors = platMajor.getName();
                            } else {
                                majors += DOUHAO + platMajor.getName();
                            }
                        }
                    } catch (Exception e) {
                        error("查询适用专业失败", e);
                    }
                }

            }
            platLessonPO.setMajors(majors);

            PlatLessonChapterTypeExample platLessonChapterTypeExample = new PlatLessonChapterTypeExample();
            PlatLessonChapterTypeExample.Criteria platLessonChapterTypeCriteria = platLessonChapterTypeExample.createCriteria();
            platLessonChapterTypeCriteria.andLessonIdEqualTo(platLessonPO.getId());
            platLessonPO.setChapterTypeNum(platLessonChapterTypeMapper.selectByExample(platLessonChapterTypeExample).size());
        }
        return list;
    }

    @Override
    public void delLesson(Long id) {
        platLessonMapper.deleteByPrimaryKey(id);

        if (true) {
            PlatLessonScheduleExample example = new PlatLessonScheduleExample();
            PlatLessonScheduleExample.Criteria criteria = example.createCriteria();
            criteria.andLessonIdEqualTo(id);
            platLessonScheduleMapper.deleteByExample(example);
        }
        if (true) {
            PlatLessonStudentExample example = new PlatLessonStudentExample();
            PlatLessonStudentExample.Criteria criteria = example.createCriteria();
            criteria.andLessonIdEqualTo(id);
            platLessonStudentMapper.deleteByExample(example);
        }
    }

    @Override
    public LessonHomeVO lessonHome(HttpServletRequest request) {
        LessonHomeVO lessonHomeVO = new LessonHomeVO();

        //当前用户
        PlatUser loginUser = platUserService.getLoginUser(request);
        if (loginUser.getRole() == ROLE_STUDENT) {
            //未开始的课程
            List<PlatLesson> list = myStudentLessonListData(myStudentLessonList(new PlatLesson(), loginUser));
            for (PlatLesson platLesson : list) {
                if (platLesson.getStudentStateCountans() == 1) {
                    //已结束
                    lessonHomeVO.setEndLessonNum(lessonHomeVO.getEndLessonNum() + 1);
                } else {
                    //未开始
                    lessonHomeVO.setNotStartLessonNum(lessonHomeVO.getNotStartLessonNum() + 1);

                    //本周课程
                    try {
                        Date date = new SimpleDateFormat(DateUtils.YYYY_MM_DD_HH_MM_SS).parse(platLesson.getLessonTime());
                        if (date.getTime() >= DateUtils.getWeekTime()[0].getTime() && date.getTime() <= DateUtils.getWeekTime()[1].getTime()) {
                            lessonHomeVO.setLessonWeekIngNum(lessonHomeVO.getLessonWeekIngNum() + 1);
                        }
                    } catch (ParseException e) {
                        error("时间转换失败", e);
                    }

                    //本月课程
                    try {
                        Date date = new SimpleDateFormat(DateUtils.YYYY_MM_DD_HH_MM_SS).parse(platLesson.getLessonTime());
                        if (date.getTime() >= DateUtils.getMonthTime()[0].getTime() && date.getTime() <= DateUtils.getMonthTime()[1].getTime()) {
                            lessonHomeVO.setLessonMonthIngNum(lessonHomeVO.getLessonMonthIngNum() + 1);
                        }
                    } catch (ParseException e) {
                        error("时间转换失败", e);
                    }
                }
            }
        }

        //当前教师的课程
        if(true){
            PlatLessonExample example = new PlatLessonExample();
            PlatLessonExample.Criteria criteria = example.createCriteria();
            if (loginUser.getRole() == ROLE_TEACHER) {
                criteria.andTeachersLike(LIKE + loginUser.getId() + LIKE);
            }
            List<PlatLesson> list = platLessonMapper.selectByExample(example);
            //课程总数
            lessonHomeVO.setAllLessonNum(list.size());
        }

        //设置的课程
        if (loginUser.getRole() == ROLE_TEACHER) {
            PlatLessonScheduleExample platLessonScheduleExample = new PlatLessonScheduleExample();
            PlatLessonScheduleExample.Criteria exampleCriteria = platLessonScheduleExample.createCriteria();
            exampleCriteria.andTeacherIdEqualTo(loginUser.getId());
            List<PlatLessonSchedule> lessonScheduleList = platLessonScheduleMapper.selectByExample(platLessonScheduleExample);
            lessonHomeVO.setLessonIngNum(lessonScheduleList.size());
        }

        //设置的课程-本周课程
        if (true) {
            // 本周结束时间
            Date endTime = DateUtils.getWeekTime()[1];

            if (loginUser.getRole() == ROLE_TEACHER) {
                PlatLessonScheduleExample platLessonScheduleExample = new PlatLessonScheduleExample();
                PlatLessonScheduleExample.Criteria exampleCriteria = platLessonScheduleExample.createCriteria();
                exampleCriteria.andTeacherIdEqualTo(loginUser.getId());
                exampleCriteria.andLessonTimeBetween(new SimpleDateFormat(DateUtils.YYYY_MM_DD_HH_MM_SS).format(DateUtils.getWeekTime()[0]), new SimpleDateFormat(DateUtils.YYYY_MM_DD_HH_MM_SS).format(endTime));
                List<PlatLessonSchedule> lessonScheduleList = platLessonScheduleMapper.selectByExample(platLessonScheduleExample);
                lessonHomeVO.setLessonWeekIngNum(lessonScheduleList.size());
            }
        }

        //设置的课程-本月课程
        if (true) {
            Date endTime = DateUtils.getMonthTime()[1];

            if (loginUser.getRole() == ROLE_TEACHER) {
                PlatLessonScheduleExample platLessonScheduleExample = new PlatLessonScheduleExample();
                PlatLessonScheduleExample.Criteria exampleCriteria = platLessonScheduleExample.createCriteria();
                exampleCriteria.andTeacherIdEqualTo(loginUser.getId());
                exampleCriteria.andLessonTimeBetween(new SimpleDateFormat(DateUtils.YYYY_MM_DD_HH_MM_SS).format(DateUtils.getMonthTime()[0]), new SimpleDateFormat(DateUtils.YYYY_MM_DD_HH_MM_SS).format(endTime));
                List<PlatLessonSchedule> lessonScheduleList = platLessonScheduleMapper.selectByExample(platLessonScheduleExample);
                lessonHomeVO.setLessonMonthIngNum(lessonScheduleList.size());
            }
        }

        //学院总数
        if (true) {
            PlatCollegeExample example = new PlatCollegeExample();
            lessonHomeVO.setCollegeNum(platCollegeMapper.selectByExample(example).size());
        }

        //专业总数
        if (true) {
            PlatMajorExample example = new PlatMajorExample();
            lessonHomeVO.setMajorNum(platMajorMapper.selectByExample(example).size());
        }

        //班级总数
        if (true) {
            PlatClassExample example = new PlatClassExample();
            lessonHomeVO.setClassNum(platClassMapper.selectByExample(example).size());
        }

        //学院人数
        if (true) {
            PlatUserExample example = new PlatUserExample();
            lessonHomeVO.setUserNum(platUserMapper.selectByExample(example).size());
        }

        //超管人数
        if (loginUser.getRole() == ROLE_SUPER_ADMIN || loginUser.getRole() == ROLE_ADMIN) {
            PlatUserExample example = new PlatUserExample();
            PlatUserExample.Criteria exampleCriteria = example.createCriteria();
            exampleCriteria.andRoleEqualTo(ROLE_SUPER_ADMIN);
            lessonHomeVO.setSuperNum(platUserMapper.selectByExample(example).size());
        }

        //普管人数
        if (loginUser.getRole() == ROLE_SUPER_ADMIN || loginUser.getRole() == ROLE_ADMIN) {
            PlatUserExample example = new PlatUserExample();
            PlatUserExample.Criteria exampleCriteria = example.createCriteria();
            exampleCriteria.andRoleEqualTo(ROLE_ADMIN);
            lessonHomeVO.setAdminNum(platUserMapper.selectByExample(example).size());
        }

        //教师人数
        if (loginUser.getRole() == ROLE_SUPER_ADMIN || loginUser.getRole() == ROLE_ADMIN) {
            PlatUserExample example = new PlatUserExample();
            PlatUserExample.Criteria exampleCriteria = example.createCriteria();
            exampleCriteria.andRoleEqualTo(ROLE_TEACHER);
            lessonHomeVO.setTeacherNum(platUserMapper.selectByExample(example).size());
        }

        //学生人数
        if (loginUser.getRole() == ROLE_SUPER_ADMIN || loginUser.getRole() == ROLE_ADMIN) {
            PlatUserExample example = new PlatUserExample();
            PlatUserExample.Criteria exampleCriteria = example.createCriteria();
            exampleCriteria.andRoleEqualTo(ROLE_STUDENT);
            lessonHomeVO.setStudentNum(platUserMapper.selectByExample(example).size());
        }
        return lessonHomeVO;
    }

    @Override
    public List<PlatLessonSchedule> myLessonScheduleList(PlatUser platUser, PlatUser loginUser,String lessonTypeId,String name) {
        List<PlatLessonSchedule> lessonScheduleList = platLessonScheduleMapper.selectList(loginUser.getId(),platUser.getClassId(),lessonTypeId,name);
        for(PlatLessonSchedule lessonSchedule:lessonScheduleList){
            PlatLessonStudentExample example = new PlatLessonStudentExample();
            PlatLessonStudentExample.Criteria criteria = example.createCriteria();
            criteria.andScheduleIdEqualTo(lessonSchedule.getId());
            List<PlatLessonStudent> list = platLessonStudentMapper.selectByExample(example);
            lessonSchedule.setUserNum(list.size());
        }
        return lessonScheduleList;
    }

    @Override
    public PlatTableDataInfo myLessonScheduleListData(PlatTableDataInfo platTableDataInfo) {
        List<LessonScheduleVO> result = new ArrayList<>();
        List<PlatLessonSchedule> platLessonScheduleList = (List<PlatLessonSchedule>) platTableDataInfo.getData();
        for (PlatLessonSchedule platLessonSchedule : platLessonScheduleList) {
            PlatLesson platLessonPO = platLessonMapper.selectByPrimaryKey(platLessonSchedule.getLessonId());
            if (platLessonPO == null) {
                continue;
            }

            //课程信息
            LessonScheduleVO lessonScheduleVO = new LessonScheduleVO();
            lessonScheduleVO.setLessonId(platLessonSchedule.getLessonId());
            lessonScheduleVO.setLessonName(platLessonPO == null ? "" : platLessonPO.getName());
            lessonScheduleVO.setClassId(platLessonSchedule.getClassId());
            lessonScheduleVO.setUserNum(platLessonSchedule.getUserNum());
            lessonScheduleVO.setCreateTime(platLessonSchedule.getCreateTime());

            PlatClass platClass = platClassMapper.selectByPrimaryKey(platLessonSchedule.getClassId());
            if (platClass != null) {
                lessonScheduleVO.setClassName(platClass.getName());
            }

            lessonScheduleVO.setLessonTime(platLessonSchedule.getLessonTime());
            lessonScheduleVO.setScheduleId(platLessonSchedule.getId());

            platLessonPO.setTypeName(getPlatLessonTypeName(null, platLessonPO.getTypeId()));
            lessonScheduleVO.setTypeName(getPlatLessonTypeName(null, platLessonPO.getTypeId()));
            result.add(lessonScheduleVO);
        }
        platTableDataInfo.setData(result);
        return platTableDataInfo;
    }

    public List<LessonScheduleVO> myLessonScheduleListOld(PlatLesson platLesson, HttpServletRequest request) {
        List<LessonScheduleVO> result = new ArrayList<>();

        //当前用户
        PlatUser loginUser = platUserService.getLoginUser(request);
        //当前教师的课程
        PlatLessonExample example = new PlatLessonExample();
        example.setOrderByClause("type_id," + orderByNumber);
        PlatLessonExample.Criteria criteria = example.createCriteria();
        criteria.andTeachersLike(LIKE + loginUser.getId() + LIKE);
        if (!StringUtils.isEmpty(platLesson.getName())) {
            criteria.andNameLike(LIKE + platLesson.getName() + LIKE);
        }
        List<PlatLesson> list = platLessonMapper.selectByExample(example);
        for (PlatLesson platPO : list) {
            PlatLessonScheduleExample platLessonScheduleExample = new PlatLessonScheduleExample();
            PlatLessonScheduleExample.Criteria exampleCriteria = platLessonScheduleExample.createCriteria();
            exampleCriteria.andLessonIdEqualTo(platPO.getId());
            exampleCriteria.andTeacherIdEqualTo(loginUser.getId());
            List<PlatLessonSchedule> lessonScheduleList = platLessonScheduleMapper.selectByExample(platLessonScheduleExample);

            //课程信息
            LessonScheduleVO scheduleVO = new LessonScheduleVO();
            scheduleVO.setLessonId(platPO.getId());
            scheduleVO.setLessonName(platPO.getName());
            scheduleVO.setTypeName(getPlatLessonTypeName(platLesson, platPO.getTypeId()));
            result.add(scheduleVO);

            for (PlatLessonSchedule platLessonSchedule : lessonScheduleList) {
                //课程信息
                LessonScheduleVO lessonScheduleVO = new LessonScheduleVO();
                lessonScheduleVO.setLessonId(platPO.getId());
                lessonScheduleVO.setLessonName(platPO.getName());
                lessonScheduleVO.setClassId(platLessonSchedule.getClassId());

                PlatClass platClass = platClassMapper.selectByPrimaryKey(platLessonSchedule.getClassId());
                if (platClass != null) {
                    lessonScheduleVO.setClassName(platClass.getName());
                }

                lessonScheduleVO.setLessonTime(platLessonSchedule.getLessonTime());
                lessonScheduleVO.setScheduleId(platLessonSchedule.getId());

                lessonScheduleVO.setTypeName(getPlatLessonTypeName(platLesson, platPO.getTypeId()));
                result.add(lessonScheduleVO);
            }
        }
        return result;
    }

    @Override
    public List<PlatLesson> myLessonList(PlatLesson platLesson, HttpServletRequest request, PlatUser platUser) {
        //当前教师的课程
        PlatLessonExample example = new PlatLessonExample();
        PlatLessonExample.Criteria criteria = example.createCriteria();
        criteria.andTeachersLike(LIKE + platUser.getId() + LIKE);
        if (!StringUtils.isEmpty(platLesson.getName())) {
            criteria.andNameLike(LIKE + platLesson.getName() + LIKE);
        }
        if (platLesson.getTypeId() != null) {
            criteria.andTypeIdLike(LIKE + platLesson.getTypeId() + LIKE);
        }
        if (!StringUtils.isEmpty(platLesson.getLabelId())) {
            criteria.andLabelIdLike(LIKE  + IDENTIFICATION +  platLesson.getLabelId()  + IDENTIFICATION +  LIKE);
        }
        if (platUser.getRole() == ROLE_TEACHER) {
            criteria.andTeachersLike(LIKE + platUser.getId() + LIKE);
        }

        example.setOrderByClause("type_id," + orderByNumber);
        List<PlatLesson> list = platLessonMapper.selectByExample(example);
        for (PlatLesson platLessonPO : list) {
            platLessonPO.setTypeName(getPlatLessonTypeName(platLesson, platLessonPO.getTypeId()));
        }
        return list;
    }

    @Override
    public List<PlatLessonStudent> myStudentLessonList(PlatLesson platLesson, PlatUser loginUser) {
        //当前学生的课程
        PlatLessonStudentExample example = new PlatLessonStudentExample();
        PlatLessonStudentExample.Criteria criteria = example.createCriteria();
        criteria.andUserIdEqualTo(loginUser.getId());
        /*if(!StringUtils.isEmpty(platLesson.getName())){
            criteria.an(LIKE + loginUser.getId() + LIKE);
        }*/
        if (platLesson.getStudentStateCountans() != null) {
            criteria.andStateEqualTo(platLesson.getStudentStateCountans());
        } else {
            criteria.andStateNotEqualTo(STATE_DELETE);
        }
        List<PlatLessonStudent> list = platLessonStudentMapper.selectByExample(example);

        for (PlatLessonStudent lessonStudent : list) {
            PlatLesson platLessonPO = platLessonMapper.selectByPrimaryKey(lessonStudent.getLessonId());
            lessonStudent.setLessonName(platLessonPO == null ? "" : platLessonPO.getName());
        }
        return list;
    }

    public List<PlatLesson> myStudentLessonListData(List<PlatLessonStudent> lessonStudentList) {
        List<PlatLesson> lessonList = new ArrayList<>();
        for (PlatLessonStudent platLessonStudent : lessonStudentList) {
            PlatLesson platLessonPO = platLessonMapper.selectByPrimaryKey(platLessonStudent.getLessonId());
            if (platLessonPO != null) {
                PlatLessonSchedule platLessonSchedule = platLessonScheduleMapper.selectByPrimaryKey(platLessonStudent.getScheduleId());
                if (platLessonSchedule != null) {
                    platLessonPO.setLessonTime(platLessonSchedule.getLessonTime());
                }
                platLessonPO.setPlatLessonStudentId(platLessonStudent.getId());
                if(platLessonStudent.getState() == 1){
                    platLessonPO.setStudentState("已结束");
                }else{
                    platLessonPO.setStudentState("未开始");
                    //答案列表
                    PlatLessonStudentAnswerExample platLessonStudentAnswerExample = new PlatLessonStudentAnswerExample();
                    PlatLessonStudentAnswerExample.Criteria platLessonStudentAnswerExampleCriteria = platLessonStudentAnswerExample.createCriteria();
                    platLessonStudentAnswerExampleCriteria.andLessonStudentIdEqualTo(platLessonStudent.getId());
                    List<PlatLessonStudentAnswer> lessonStudentAnswerList = PlatLessonStudentAnswerMapper.selectByExample(platLessonStudentAnswerExample);
                    if(lessonStudentAnswerList.size()>0){
                        platLessonPO.setStudentState("已开始");
                    }
                }

                platLessonPO.setStudentStateCountans(platLessonStudent.getState());
                platLessonPO.setTypeName(getPlatLessonTypeName(null, platLessonPO.getTypeId()));
                lessonList.add(platLessonPO);
            }
        }
        return lessonList;
    }

    public static void main(String[] args) {
        new PlatLessonServiceImpl().addLessonSchedule(null,null);
    }

    @Override
    public void addLessonSchedule(PlatLessonSchedule platLessonSchedule, HttpServletRequest request) {
        /*if(true){
            String str =
                    "。1，设计健康体检套餐，设计健康体检套餐--脑卒中" +
                    "。1，设计健康体检套餐，设计健康体检套餐--糖尿病" +
                    "。1，健康体检报告解读，健康体检报告解读--乳腺癌和甲状腺" +
                    "。1，健康体检报告解读，健康体检报告解读--脑卒中和外周血管疾病" +
                    "。1，区域性健康风险评估，企业人群健康数据分析" +
                    "。1，区域性健康风险评估，社区人群健康数据分析" +
                    "。1，区域性健康风险评估，养老院人群健康数据分析" +
                    "。2，慢性病健康干预，慢性病健康干预-高血压" +
                    "。2，慢性病健康干预，慢性病健康干预-脑卒中" +
                    "。2，慢性病健康干预，慢性病健康干预-肥胖症" +
                    "。2，慢性病健康干预，慢性病健康干预-慢性阻塞性肺病" +
                    "。2，慢性病健康干预，慢性病健康干预-骨质疏松" +
                    "。2，慢性病健康干预，慢性病健康干预-盆底功能障碍" +
                    "。2，慢性病健康干预，慢性病健康干预-冠心病" +
                    "。2，慢性病健康干预，慢性病健康干预-糖尿病" +
                    "。2，慢病健康评估，健康促进生活方式评估" +
                    "。2，慢病健康评估，中医九种体质评估" +
                    "。2，慢病健康评估，睡眠质量评估" +
                    "。2，慢病健康评估，慢性病人生活质量评估" +
                    "。2，慢病健康评估，跌倒风险评估" +
                    "。2，慢病健康评估，认知能力评估" +
                    "。2，慢病健康评估，日常生活活动能力评估" +
                    "。2，慢病健康评估，亚健康状态人群10种慢性病风险评估" +
                    "。2，慢病健康评估，孤独量评估" +
                    "。2，慢病健康评估，社交回避及苦恼量评估" +
                    "。2，慢病健康评估，各种常用心理学评估" +
                    "。2，慢性病风险模型评估，心血管病风险评估" +
                    "。2，慢性病风险模型评估，脑卒中风险评估" +
                    "。2，慢性病风险模型评估，糖尿病风险评估" +
                    "。2，慢性病风险模型评估，慢性阻塞性肺疾病风险评估" +
                    "。3，食材分类游戏，食材分类游戏" +
                    "。3，特殊人群配餐，慢性病饮食干预-高血压" +
                    "。3，特殊人群配餐，慢性病饮食干预-冠心病" +
                    "。3，特殊人群配餐，慢性病饮食干预-脑卒中" +
                    "。3，特殊人群配餐，慢性病饮食干预-糖尿病" +
                    "。3，特殊人群配餐，慢性病饮食干预-肥胖症" +
                    "。3，特殊人群配餐，慢性病饮食干预-慢性阻塞性肺病" +
                    "。3，特殊人群配餐，慢性病饮食干预-骨质疏松" +
                    "。3，特殊人群配餐，慢性病饮食干预-盆底功能障碍" +
                    "。3，营养标签游戏，正常人群食品标签实验" +
                    "。3，营养标签游戏，高血压患者食品标签实验" +
                    "。3，营养标签游戏，糖尿病患者食品标签实验" +
                    "。4，运动综合评估及训练，BMI训练" +
                    "。4，运动综合评估及训练，反应力能力训练" +
                    "。4，运动综合评估及训练，肺功能能力训练" +
                    "。4，运动综合评估及训练，核心力能力训练" +
                    "。4，运动综合评估及训练，心功能能力训练" +
                    "。4，运动综合评估及训练，本体感觉训练" +
                    "。4，运动综合评估及训练，床上操" +
                    "。4，运动综合评估及训练，养生操" +
                    "。4，运动综合评估及训练，家务运动训练" +
                    "。4，运动综合评估及训练，徒手保健养生操（75岁以下）" +
                    "。4，运动综合评估及训练，徒手保健养生操（75岁以上）" +
                    "。4，运动综合评估及训练，懒人训练" +
                    "。4，运动综合评估及训练，局部力量训练" +
                    "。4，运动综合评估及训练，平衡能力评估" +
                    "。4，运动综合评估及训练，柔软度能力训练" +
                    "。4，运动综合评估及训练，协调能力训练" +
                    "。5，设计健康体检套餐，设计健康体检套餐--脑卒中" +
                    "。5，设计健康体检套餐，设计健康体检套餐--糖尿病" +
                    "。5，健康体检报告解读，健康体检报告解读--乳腺癌和甲状腺" +
                    "。5，健康体检报告解读，健康体检报告解读--脑卒中和外周血管疾病" +
                    "。5，区域性健康风险评估，企业人群健康数据分析" +
                    "。5，区域性健康风险评估，社区人群健康数据分析" +
                    "。5，区域性健康风险评估，养老院人群健康数据分析" +
                    "。5，慢病健康评估，孤独量评估" +
                    "。5，慢病健康评估，社交回避及苦恼量评估" +
                    "。5，慢性病健康干预，慢性病健康干预-高血压" +
                    "。5，慢性病健康干预，慢性病健康干预-脑卒中" +
                    "。5，慢性病健康干预，慢性病健康干预-肥胖症" +
                    "。5，慢性病健康干预，慢性病健康干预-慢性阻塞性肺病" +
                    "。5，慢性病健康干预，慢性病健康干预-骨质疏松" +
                    "。5，慢性病健康干预，慢性病健康干预-盆底功能障碍" +
                    "。5，慢性病健康干预，慢性病健康干预-冠心病" +
                    "。5，慢性病健康干预，慢性病健康干预-糖尿病" +
                    "。5，健康综合评估，健康促进生活方式评估" +
                    "。5，健康综合评估，中医九种体质评估" +
                    "。5，健康综合评估，睡眠质量评估" +
                    "。5，健康综合评估，慢性病人生活质量评估" +
                    "。5，健康综合评估，跌倒风险评估" +
                    "。5，健康综合评估，认知能力评估" +
                    "。5，健康综合评估，日常生活活动能力评估" +
                    "。5，健康综合评估，亚健康状态人群10种慢性病风险评估" +
                    "。5，健康综合评估，各种常用心理学评估" +
                    "。5，慢性病风险模型评估，心血管病风险评估" +
                    "。5，慢性病风险模型评估，脑卒中风险评估" +
                    "。5，慢性病风险模型评估，糖尿病风险评估" +
                    "。5，慢性病风险模型评估，慢性阻塞性肺疾病风险评估" +
                    "。5，食材分类游戏，食材分类游戏" +
                    "。5，慢性病饮食干预，慢性病饮食干预-高血压" +
                    "。5，慢性病饮食干预，慢性病饮食干预-冠心病" +
                    "。5，慢性病饮食干预，慢性病饮食干预-脑卒中" +
                    "。5，慢性病饮食干预，慢性病饮食干预-糖尿病" +
                    "。5，慢性病饮食干预，慢性病饮食干预-肥胖症" +
                    "。5，慢性病饮食干预，慢性病饮食干预-慢性阻塞性肺病" +
                    "。5，慢性病饮食干预，慢性病饮食干预-骨质疏松" +
                    "。5，慢性病饮食干预，慢性病饮食干预-盆底功能障碍" +
                    "。5，营养标签游戏，正常人群食品标签实验" +
                    "。5，营养标签游戏，高血压患者食品标签实验" +
                    "。5，营养标签游戏，糖尿病患者食品标签实验" +
                    "。5，运动功能检测与评估，BMI训练" +
                    "。5，运动功能检测与评估，反应力能力训练" +
                    "。5，运动功能检测与评估，肺功能能力训练" +
                    "。5，运动功能检测与评估，核心力能力训练" +
                    "。5，运动功能检测与评估，心功能能力训练" +
                    "。5，运动功能检测与评估，本体感觉训练" +
                    "。5，运动功能检测与评估，局部力量训练" +
                    "。5，运动功能检测与评估，平衡能力评估" +
                    "。5，运动功能检测与评估，柔软度能力训练" +
                    "。5，运动功能检测与评估，协调能力训练" +
                    "。5，运动综合评估及训练，床上操" +
                    "。5，运动综合评估及训练，养生操" +
                    "。5，运动综合评估及训练，家务运动训练" +
                    "。5，运动综合评估及训练，徒手保健养生操（75岁以下）" +
                    "。5，运动综合评估及训练，徒手保健养生操（75岁以上）" +
                    "。5，运动综合评估及训练，懒人训练" +
                    "。5，设计健康体检套餐，设计健康体检套餐--肺癌+COPD" +
                    "。5，设计健康体检套餐，设计健康体检套餐--乳腺癌" +
                    "。5，设计健康体检套餐，设计健康体检套餐--宫颈癌" +
                    "。5，设计健康体检套餐，设计健康体检套餐--胃癌" +
                    "。5，设计健康体检套餐，设计健康体检套餐--直结肠癌" +
                    "。5，设计健康体检套餐，设计健康体检套餐--前列腺癌" +
                    "。5，设计健康体检套餐，设计健康体检套餐--慢性肾病CKD" +
                    "。5，设计健康体检套餐，设计健康体检套餐--外周血管疾病" +
                    "。5，设计健康体检套餐，设计健康体检套餐--冠心病和高血压" +
                    "。5，健康体检报告解读，健康体检报告解读--大学生体适能测量案例" +
                    "。5，健康体检报告解读，健康体检报告解读--前列腺癌案例" +
                    "。5，健康体检报告解读，健康体检报告解读--宫颈癌案例" +
                    "。5，健康体检报告解读，健康体检报告解读--化验单案例" +
                    "。5，健康体检报告解读，健康体检报告解读--高血压、冠心病案例" +
                    "。5，健康体检报告解读，健康体检报告解读--糖尿病案例" +
                    "。5，特殊人群沟通技能，与依从性差的高血压病患者沟通" +
                    "。5，特殊人群沟通技能，通俗易懂的回答患者问题" +
                    "。5，特殊人群沟通技能，有恰当人文关怀的医患沟通" +
                    "。5，健康调查问卷分析，问卷设计中常见的错误类型（一）" +
                    "。5，健康调查问卷分析，问卷设计中常见的错误类型（二）" +
                    "。5，健康调查问卷分析，问卷设计中常见的错误类型（三）" +
                    "。5，健康调查问卷设计，大学生健康问题调查表设计" +
                    "。5，健康调查问卷设计，企业员工健康问题调查表设计" +
                    "。5，健康调查问卷设计，老年人健康问题调查表设计" +
                    "。5，营养标签游戏，正常人群营养标签游戏" +
                    "。5，群体健康管理，养老院健康服务与管理技能" +
                    "。5，群体健康管理，社区健康服务与管理技能" +
                    "。5，群体健康管理，企业健康服务与管理技能" +
                    "。5，健康保险，健康保险投保" +
                    "。5，健康保险，健康保险理赔" +
                    "。5，专项护理评估，Barthel指数评定" +
                    "。5，专项护理评估，社会生活能力评估" +
                    "。5，专项护理评估，压力性损伤风险评估" +
                    "。5，专项护理评估，疼痛评估" +
                    "。5，老年人心理护理，老年人心理误区" +
                    "。5，老年人心理护理，老年人常见心理变化" +
                    "。5，老年人心理护理，老年人心理变化的影响因素" +
                    "。5，老年人心理护理，老年人常见心理问题" +
                    "。5，老年人心理护理，老年人抑郁及心理护理" +
                    "。5，老年人心理护理，老年人焦虑及心理护理" +
                    "。5，老年人心理护理，老年人酒精依赖及心理护理" +
                    "。5，老年人心理护理，老年人烟草依赖及心理护理" +
                    "。5，老年人心理护理，老年人药物依赖及心理护理" +
                    "。5，老年人心理护理，老年人丧偶、再婚及心理护理" +
                    "。5，老年人心理护理，老年人离退休综合征及心理护理" +
                    "。5，老年人心理护理，空巢老年人及心理护理" +
                    "。5，老年人心理护理，老年人自杀及心理护理" +
                    "。5，老年人心理护理，老年人痴呆心理护理" +
                    "。5，老年人心理护理，老年人冠心病及心理护理" +
                    "。5，老年人心理护理，老年人消化性溃疡及心理护理" +
                    "。5，老年人心理护理，老年人原发性高血压及心理护理" +
                    "。5，老年人心理护理，老年人心身疾病及心理护理" +
                    "。5，老年人心理护理，指导老年人练习太极拳" +
                    "。5，老年人心理护理，指导老年人开展游泳活动" +
                    "。5，老年人心理护理，指导老年人开展音乐活动" +
                    "。5，老年人心理护理，指导老年人开展读书活动" +
                    "。5，老年人心理护理，对临终老年人的心理护理" +
                    "。5，老年人心理护理，帮助老年人正确对待生死" +
                    "。5，老年人心理护理，正确认识临终关怀" +
                    "。5，养老护理员职业素养，养老护理员的技能要求" +
                    "。5，养老护理员职业素养，养老护理员的专业知识" +
                    "。5，养老护理员职业素养，养老护理员的职业道德修养" +
                    "。5，养老护理员职业素养，养老护理员的心理素质" +
                    "。8，设计健康体检套餐，设计健康体检套餐--糖尿病" +
                    "。8，设计健康体检套餐，设计健康体检套餐--冠心病和高血压" +
                    "。8，健康综合评估，健康促进生活方式评估" +
                    "。8，健康综合评估，中医九种体质评估" +
                    "。8，健康综合评估，睡眠质量评估" +
                    "。8，健康综合评估，慢性病人生活质量评估" +
                    "。8，健康综合评估，跌倒风险评估" +
                    "。8，健康综合评估，认知能力评估" +
                    "。8，健康综合评估，日常生活活动能力评估" +
                    "。8，健康综合评估，亚健康状态人群10种慢性病风险评估" +
                    "。8，健康综合评估，各种常用心理学评估" +
                    "。8，慢性病健康干预，慢性病健康干预-冠心病" +
                    "。8，慢性病健康干预，慢性病健康干预-糖尿病" +
                    "。8，慢性病风险模型评估，心血管病风险评估" +
                    "。8，慢性病风险模型评估，脑卒中风险评估" +
                    "。8，慢性病风险模型评估，糖尿病风险评估" +
                    "。8，慢性病风险模型评估，慢性阻塞性肺疾病风险评估" +
                    "。8，运动功能检测与评估，局部力量训练" +
                    "。8，运动功能检测与评估，平衡能力评估" +
                    "。8，运动功能检测与评估，柔软度能力训练" +
                    "。8，运动功能检测与评估，协调能力训练" +
                    "。8，健康体检报告解读，健康体检报告解读--高血压、冠心病案例" +
                    "。8，健康体检报告解读，健康体检报告解读--糖尿病案例";

            Map<String,String> map = new HashMap();

            String[] arrays = str.split("。");
            for(String h:arrays){
                if(!h.contains("，")){
                    continue;
                }
                String[] L = h.split("，");
                *//*if(map.get(L[0]+L[1])==null){
                    System.out.println("INSERT INTO `plat_lesson_label` VALUES (null, '"+L[1]+"', 'now()', null, "+L[0]+");");
                    map.put(L[0]+L[1],"x");
                }*//*
                String label = L[1];
                String lessonName = L[2];

                List<PlatLesson> lessonList = null;
                if(true){
                    PlatLessonExample example = new PlatLessonExample();
                    PlatLessonExample.Criteria exampleCriteria = example.createCriteria();
                    exampleCriteria.andNameEqualTo(lessonName);
                    lessonList = platLessonMapper.selectByExample(example);
                }

                if(lessonList.size()!=1){
                    System.out.println("有错误:"+lessonName+".不存在");
                    return;
                }
                PlatLesson platLesson = lessonList.get(0);

                List<PlatLessonLabel> labelList = null;
                String lab = "";
                if(true){
                    if(true){
                        PlatLessonLabelExample example = new PlatLessonLabelExample();
                        PlatLessonLabelExample.Criteria exampleCriteria = example.createCriteria();
                        exampleCriteria.andNameEqualTo(label);
                        labelList = platLessonLabelMapper.selectByExample(example);
                    }

                    if(labelList.size()==0){
                        System.out.println("有错误");
                        return;
                    }
                    for(PlatLessonLabel lessonLabel:labelList){
                        PlatLessonExample example = new PlatLessonExample();
                        PlatLessonExample.Criteria exampleCriteria = example.createCriteria();
                        exampleCriteria.andNameEqualTo(lessonName);
                        lessonList = platLessonMapper.selectByExample(example);
                        platLesson = lessonList.get(0);

                        if(platLesson.getLabelId()!=null && platLesson.getLabelId().contains("@"+lessonLabel.getId()+"@")){
                            continue;
                        }

                        if(platLesson.getLabelId()==null){
                            platLesson.setLabelId("@"+lessonLabel.getId()+"@");
                        }else{
                            platLesson.setLabelId(platLesson.getLabelId()+lessonLabel.getId()+"@");
                        }
                        platLessonMapper.updateByPrimaryKey(platLesson);
                    }
                }



            }
            return;
        }*/

        //当前用户
        PlatUser loginUser = platUserService.getLoginUser(request);
        platLessonSchedule.setTeacherId(loginUser.getId());

        if (platLessonSchedule.getId() == null) {
            platLessonSchedule.setCreateTime(new Date());
            platLessonScheduleMapper.insert(platLessonSchedule);

            //查询当前班级的学生
            PlatUserExample example = new PlatUserExample();
            PlatUserExample.Criteria exampleCriteria = example.createCriteria();
            exampleCriteria.andRoleEqualTo(ROLE_STUDENT);
            exampleCriteria.andClassIdEqualTo(platLessonSchedule.getClassId());
            List<PlatUser> list = platUserMapper.selectByExample(example);
            for (PlatUser platUser : list) {
                PlatLessonStudent platLessonStudent = new PlatLessonStudent();
                platLessonStudent.setLessonId(platLessonSchedule.getLessonId());
                platLessonStudent.setUserId(platUser.getId());
                platLessonStudent.setState(0);
                platLessonStudent.setCreateTime(new Date());
                platLessonStudent.setScheduleId(platLessonSchedule.getId());
                platLessonStudent.setClassId(platUser.getClassId());
                platLessonStudent.setScore("");
                platLessonStudent.setCompleteTime("");
                platLessonStudentMapper.insert(platLessonStudent);
            }
        } else {
            platLessonSchedule.setUpdateTime(new Date());
            platLessonScheduleMapper.updateByPrimaryKeySelective(platLessonSchedule);
        }
    }

    @Override
    public void delLessonSchedule(Long id) {
        platLessonScheduleMapper.deleteByPrimaryKey(id);

        PlatLessonStudentExample example = new PlatLessonStudentExample();
        PlatLessonStudentExample.Criteria exampleCriteria = example.createCriteria();
        exampleCriteria.andScheduleIdEqualTo(id);
        platLessonStudentMapper.deleteByExample(example);
    }

    @Override
    public List<LessonFullCalendarVO> myLessonFullCalendarList(HttpServletRequest request) {
        List<LessonFullCalendarVO> result = new ArrayList<>();

        //当前用户
        PlatUser loginUser = platUserService.getLoginUser(request);
        if (loginUser.getRole() == ROLE_STUDENT) {
            return myLessonFullCalendarListByStudent(request);
        }

        //当前教师的课程
        PlatLessonExample example = new PlatLessonExample();
        PlatLessonExample.Criteria criteria = example.createCriteria();
        criteria.andTeachersLike(LIKE + loginUser.getId() + LIKE);
        List<PlatLesson> list = platLessonMapper.selectByExample(example);
        for (PlatLesson platPO : list) {
            PlatLessonScheduleExample platLessonScheduleExample = new PlatLessonScheduleExample();
            PlatLessonScheduleExample.Criteria exampleCriteria = platLessonScheduleExample.createCriteria();
            exampleCriteria.andLessonIdEqualTo(platPO.getId());
            exampleCriteria.andTeacherIdEqualTo(loginUser.getId());
            List<PlatLessonSchedule> lessonScheduleList = platLessonScheduleMapper.selectByExample(platLessonScheduleExample);

            for (PlatLessonSchedule platLessonSchedule : lessonScheduleList) {
                PlatClass platClass = platClassMapper.selectByPrimaryKey(platLessonSchedule.getClassId());
                if (platClass == null) {
                    continue;
                }
                LessonFullCalendarVO lessonFullCalendarVO = new LessonFullCalendarVO();
                String className = platClass.getName();
                String lessonName = platPO.getName();
                lessonFullCalendarVO.setTitle(className + "(" + lessonName + ")");
                lessonFullCalendarVO.setStart(platLessonSchedule.getLessonTime());
                lessonFullCalendarVO.setUrl("");
                result.add(lessonFullCalendarVO);
            }
        }
        return result;
    }

    public List<LessonFullCalendarVO> myLessonFullCalendarListByStudent(HttpServletRequest request) {
        List<LessonFullCalendarVO> result = new ArrayList<>();

        //当前用户
        PlatUser loginUser = platUserService.getLoginUser(request);

        PlatLesson platLessonVO = new PlatLesson();
        platLessonVO.setStudentStateCountans(0);

        List<PlatLessonStudent> lessonStudentList = myStudentLessonList(platLessonVO, loginUser);
        List<PlatLesson> list = myStudentLessonListData(lessonStudentList);

        for (PlatLesson platLesson : list) {
            LessonFullCalendarVO lessonFullCalendarVO = new LessonFullCalendarVO();
            String lessonName = platLesson.getName();
            lessonFullCalendarVO.setTitle(lessonName);
            lessonFullCalendarVO.setStart(platLesson.getLessonTime());
            lessonFullCalendarVO.setUrl("");
            result.add(lessonFullCalendarVO);
        }
        return result;
    }

    @Override
    public void endLesson(Long id) {
        PlatLessonStudent platLessonStudent = platLessonStudentMapper.selectByPrimaryKey(id);
        if (platLessonStudent != null) {
            //重做课程 删除答案
            if (platLessonStudent.getState() == 1) {
                PlatLessonStudentAnswerExample platLessonStudentAnswerExample = new PlatLessonStudentAnswerExample();
                PlatLessonStudentAnswerExample.Criteria platLessonStudentAnswerExampleCriteria = platLessonStudentAnswerExample.createCriteria();
                platLessonStudentAnswerExampleCriteria.andLessonStudentIdEqualTo(platLessonStudent.getId());
                PlatLessonStudentAnswerMapper.deleteByExample(platLessonStudentAnswerExample);

                //分数归零
                platLessonStudent.setScore("");
                //完成时间清空
                platLessonStudent.setCompleteTime("");
            }

            platLessonStudent.setState(platLessonStudent.getState() == null || platLessonStudent.getState() == 0 ? 1 : 0);
            platLessonStudentMapper.updateByPrimaryKey(platLessonStudent);
        }
    }

    @Override
    public List<PlatLessonType> lessonTypeList(PlatLessonType platLessonType,HttpServletRequest request) {
        //当前用户
        PlatUser loginUser = platUserService.getLoginUser(request);
        List<Long> values = null;
        if(loginUser.getRole() == ROLE_TEACHER){
            //当前教师的课程
            PlatLessonExample example = new PlatLessonExample();
            PlatLessonExample.Criteria criteria = example.createCriteria();
            criteria.andTeachersLike(LIKE + loginUser.getId() + LIKE);

            List<PlatLesson> list = platLessonMapper.selectByExample(example);
            Set<Long> set = new HashSet<>();
            for(PlatLesson platLesson:list){
                String str[] = platLesson.getTypeId().split(AITT);
                for(String id:str){
                    if(!StringUtils.isEmpty(id)){
                        set.add(Long.parseLong(id));
                    }
                }
            }

            values = new ArrayList<>(set);

            if(values.size()==0){
                return new ArrayList<>();
            }
        }

        //模糊查询
        PlatLessonTypeExample example = new PlatLessonTypeExample();
        PlatLessonTypeExample.Criteria criteria = example.createCriteria();
        if (!StringUtils.isEmpty(platLessonType.getName())) {
            criteria.andNameLike(LIKE + platLessonType.getName() + LIKE);
        }

        if(values!=null){
            criteria.andIdIn(values);
        }

        example.setOrderByClause("id asc");

        List<PlatLessonType> list = platLessonTypeMapper.selectByExample(example);
        return list;
    }

    //删除之前存储的
    private void deleteStudentAnswer(ReqCommonVO req, String answerType) {
        PlatLessonStudentAnswerExample example = new PlatLessonStudentAnswerExample();
        PlatLessonStudentAnswerExample.Criteria criteria = example.createCriteria();
        criteria.andLessonStudentIdEqualTo(Long.parseLong(req.getPlatLessonStudentId()));
        criteria.andLessonSonIdEqualTo(Long.parseLong(req.getPlatLessonSonId()));
        criteria.andAnswerTypeEqualTo(answerType);
        PlatLessonStudentAnswerMapper.deleteByExample(example);
    }

    //存储答案
    private void insert(ReqCommonVO req, String answer, int answerNum, int answerTrueNum, String answerType) {
        PlatLessonStudentAnswer platLessonStudentAnswer = new PlatLessonStudentAnswer();
        platLessonStudentAnswer.setLessonStudentId(Long.parseLong(req.getPlatLessonStudentId()));
        platLessonStudentAnswer.setLessonSonId(Long.parseLong(req.getPlatLessonSonId()));
        platLessonStudentAnswer.setAnswerType(answerType);
        platLessonStudentAnswer.setAnswer(answer);
        platLessonStudentAnswer.setAnswerNum(answerNum);
        platLessonStudentAnswer.setAnswerTrueNum(answerTrueNum);
        platLessonStudentAnswer.setCreateTime(new Date());
        platLessonStudentAnswer.setUpdateTime(new Date());
        PlatLessonStudentAnswerMapper.insert(platLessonStudentAnswer);
    }

    @Override
    public void lessonInAnswer(ReqCommonVO req, HttpServletRequest request) {
        //当前用户
        PlatUser loginUser = platUserService.getLoginUser(request);
        if (loginUser.getRole() != ROLE_STUDENT) {
            return;
        }

        if (req.getPlatLessonSonId() == null || !NumberUtils.isParsable(req.getPlatLessonSonId())) {
            throw new BusinessException("platLessonSonId不能为空!");
        }

        //如果不是从得分详情进入，不再更新答案
        if (req.getPlatLessonStudentId() == null || !NumberUtils.isParsable(req.getPlatLessonStudentId())) {
            return;
        }

        PlatLessonSon platLessonSon = platLessonSonMapper.selectByPrimaryKey(Long.parseLong(req.getPlatLessonSonId()));
        if (platLessonSon == null) {
            throw new BusinessException("platLessonSonId无效!");
        }

        //学习课件类
        if (req.getNullAnswer()) {
            deleteStudentAnswer(req, ReqCommonVO.STUDY_NULL_ANSWER);
            insert(req, "", 1, 1, ReqCommonVO.STUDY_NULL_ANSWER);
        }

        //选择题
        if (!CollectionUtils.isEmpty(req.getSelectRecords())) {
            deleteStudentAnswer(req, ReqCommonVO.SELECTRECORDS);

            int answerNum = 0;
            int answerTrueNum = 0;
            //存储数据库的答案
            List<List<String>> answerList = new ArrayList<>();
            for (AnswerSelectVO answerSelectVO : req.getSelectRecords()) {
                List<String> answer = answerSelectVO.getAnswer();
                answerList.add(answer);
                List<String> answerTrue = answerSelectVO.getAnswerTrue();
                answerNum++;
                if (answer.equals(answerTrue)) {
                    answerTrueNum++;
                }
            }

            String answer = null;
            try {
                answer = new ObjectMapper().writeValueAsString(answerList);
            } catch (JsonProcessingException e) {
                error("存储答案失败", e);
                throw new BusinessException("存储答案失败!");
            }

            insert(req, answer, answerNum, answerTrueNum, ReqCommonVO.SELECTRECORDS);
        }

        //填空题 不带答案
        if (!CollectionUtils.isEmpty(req.getInputRecords())) {
            deleteStudentAnswer(req, ReqCommonVO.INPUTRECORDS);

            //存储数据库的答案
            String answer = null;
            try {
                answer = new ObjectMapper().writeValueAsString(req.getInputRecords());
            } catch (JsonProcessingException e) {
                error("存储答案失败", e);
                throw new BusinessException("存储答案失败!");
            }
            insert(req, answer, 1, 1, ReqCommonVO.INPUTRECORDS);
        }

        //填空题 带答案
        if (req.getInputAnswerRecords() != null) {
            deleteStudentAnswer(req, ReqCommonVO.INPUTANSWERRECORDS);

            //存储数据库的答案
            String answer = null;
            try {
                answer = new ObjectMapper().writeValueAsString(req.getInputAnswerRecords());
            } catch (JsonProcessingException e) {
                error("存储答案失败", e);
                throw new BusinessException("存储答案失败!");
            }
            insert(req, answer, req.getAnswerNum(), req.getAnswerTrueNum(), ReqCommonVO.INPUTANSWERRECORDS);
        }

        //答案列表
        PlatLessonStudentAnswerExample platLessonStudentAnswerExample = new PlatLessonStudentAnswerExample();
        PlatLessonStudentAnswerExample.Criteria platLessonStudentAnswerExampleCriteria = platLessonStudentAnswerExample.createCriteria();
        platLessonStudentAnswerExampleCriteria.andLessonStudentIdEqualTo(Long.parseLong(req.getPlatLessonStudentId()));
        List<PlatLessonStudentAnswer> lessonStudentAnswerList = PlatLessonStudentAnswerMapper.selectByExample(platLessonStudentAnswerExample);

        //子课程id，问题数，答题正确数
        Map<Long, Integer> mapAnswerNum = new HashMap<>();
        Map<Long, Integer> mapAnswerTrueNum = new HashMap<>();
        for (PlatLessonStudentAnswer platLessonStudentAnswer : lessonStudentAnswerList) {
            if (mapAnswerNum.get(platLessonStudentAnswer.getLessonSonId()) == null) {
                mapAnswerNum.put(platLessonStudentAnswer.getLessonSonId(), platLessonStudentAnswer.getAnswerNum());
            } else {
                mapAnswerNum.put(platLessonStudentAnswer.getLessonSonId(), mapAnswerNum.get(platLessonStudentAnswer.getLessonSonId()) + platLessonStudentAnswer.getAnswerNum());
            }
            if (mapAnswerTrueNum.get(platLessonStudentAnswer.getLessonSonId()) == null) {
                mapAnswerTrueNum.put(platLessonStudentAnswer.getLessonSonId(), platLessonStudentAnswer.getAnswerTrueNum());
            } else {
                mapAnswerTrueNum.put(platLessonStudentAnswer.getLessonSonId(), mapAnswerTrueNum.get(platLessonStudentAnswer.getLessonSonId()) + platLessonStudentAnswer.getAnswerTrueNum());
            }
        }

        //子课程列表
        PlatLessonSonExample platLessonSonExample = new PlatLessonSonExample();
        PlatLessonSonExample.Criteria platLessonSonExampleCriteria = platLessonSonExample.createCriteria();
        platLessonSonExampleCriteria.andLessonIdEqualTo(platLessonSon.getLessonId());
        List<PlatLessonSon> lessonSonList = platLessonSonMapper.selectByExample(platLessonSonExample);
        //是否所有课程都答完了
        Boolean allResultFlag = true;
        //子课程id，分数百分比
        Map<Long, String> mapBfb = new HashMap<>();
        for (PlatLessonSon platLessonSonPO : lessonSonList) {
            mapBfb.put(platLessonSonPO.getId(), platLessonSonPO.getSerialNumber());
            if (mapAnswerNum.get(platLessonSonPO.getId()) == null || mapAnswerTrueNum.get(platLessonSonPO.getId()) == null) {
                allResultFlag = false;
                break;
            }
        }

        //所有题都答完了 计算分数
        String finalScore = null;
        if (allResultFlag) {
            double finalFenshu = 0;
            for (Map.Entry<Long, String> entry : mapBfb.entrySet()) {
                Long lessonSonId = entry.getKey();
                String bfb = entry.getValue();
                //正确率
                double percentage = ((double) mapAnswerTrueNum.get(lessonSonId) / mapAnswerNum.get(lessonSonId)) * 100;
                if(mapAnswerNum.get(lessonSonId)==null || mapAnswerNum.get(lessonSonId)==0){
                    percentage = 0;
                }

                //分数
                String bfbV = bfb.replace("%", "").replace(" ", "");
                //最终分数
                finalFenshu += percentage * Double.parseDouble(bfbV) / 100;
            }
            //准备四舍五入
            BigDecimal bd = new BigDecimal(finalFenshu);
            // 四舍五入到整数
            BigDecimal rounded = bd.setScale(0, RoundingMode.HALF_UP);
            finalScore = String.valueOf(rounded);
        }

        //存储分数
        if (!StringUtils.isEmpty(finalScore)) {
            PlatLessonStudentExample example = new PlatLessonStudentExample();
            PlatLessonStudentExample.Criteria criteria = example.createCriteria();
            criteria.andUserIdEqualTo(loginUser.getId());
            criteria.andLessonIdEqualTo(platLessonSon.getLessonId());
            criteria.andStateNotEqualTo(STATE_DELETE);
            List<PlatLessonStudent> list = platLessonStudentMapper.selectByExample(example);
            for (PlatLessonStudent lessonStudent : list) {
                lessonStudent.setScore(finalScore);
                lessonStudent.setCompleteTime(new SimpleDateFormat(DateUtils.YYYY_MM_DD_HH_MM_SS).format(new Date()));
                lessonStudent.setState(1);
                platLessonStudentMapper.updateByPrimaryKey(lessonStudent);
            }
        }
    }

    @Override
    public List<PlatLessonStudentAnswer> getLessonInAnswer(Long id, HttpServletRequest request) {
        //当前用户
        PlatUser loginUser = platUserService.getLoginUser(request);
        /*
        教师也可以查看学生成绩
        if (loginUser.getRole() != ROLE_STUDENT) {
            throw new BusinessException("当前角色非学生");
        }*/

        if (id == null) {
            throw new BusinessException("标识id不能为空");
        }

        PlatLessonStudent platLessonStudentPO = platLessonStudentMapper.selectByPrimaryKey(id);
        if (platLessonStudentPO == null) {
            throw new BusinessException("标识id无效");
        }
        PlatLessonStudentAnswerExample example = new PlatLessonStudentAnswerExample();
        PlatLessonStudentAnswerExample.Criteria criteria = example.createCriteria();
        criteria.andLessonStudentIdEqualTo(id);
        List<PlatLessonStudentAnswer> lessonStudentAnswerList = PlatLessonStudentAnswerMapper.selectByExample(example);
        return lessonStudentAnswerList;
    }

    @Override
    public Map<String,String> lessonSonState(Long platLessonStudentId, HttpServletRequest request) {
        Map<String,String> map = new HashMap<>();
        //答案列表
        PlatLessonStudentAnswerExample platLessonStudentAnswerExample = new PlatLessonStudentAnswerExample();
        PlatLessonStudentAnswerExample.Criteria platLessonStudentAnswerExampleCriteria = platLessonStudentAnswerExample.createCriteria();
        platLessonStudentAnswerExampleCriteria.andLessonStudentIdEqualTo(platLessonStudentId);
        List<PlatLessonStudentAnswer> lessonStudentAnswerList = PlatLessonStudentAnswerMapper.selectByExample(platLessonStudentAnswerExample);
        map.put("platLessonStudentId",String.valueOf(platLessonStudentId));
        for(PlatLessonStudentAnswer platLessonStudentAnswer:lessonStudentAnswerList){
            map.put(String.valueOf(platLessonStudentAnswer.getLessonSonId()),"已完成");
        }
        return map;
    }

    @Override
    public List<PlatLessonLabel> getLabelByType(Long typeId, HttpServletRequest request) {
        PlatLessonLabelExample example = new PlatLessonLabelExample();
        PlatLessonLabelExample.Criteria criteria = example.createCriteria();
        criteria.andTypeIdEqualTo(typeId);
        List<PlatLessonLabel> list = platLessonLabelMapper.selectByExample(example);
        return list;
    }

    @Override
    public List<PlatUser> myLessonStudentList(Long scheduleId,String name) {
        List<PlatUser> list = platUserMapper.myLessonStudentList(scheduleId,name);
        for(PlatUser platUser:list){
            PlatLessonStudentAnswerExample platLessonStudentAnswerExample = new PlatLessonStudentAnswerExample();
            PlatLessonStudentAnswerExample.Criteria platLessonStudentAnswerExampleCriteria = platLessonStudentAnswerExample.createCriteria();
            platLessonStudentAnswerExampleCriteria.andLessonStudentIdEqualTo(platUser.getId());
            List<PlatLessonStudentAnswer> answerList = PlatLessonStudentAnswerMapper.selectByExample(platLessonStudentAnswerExample);
            if(answerList.size()==0){
                platUser.setScoreState("未开始");
            }else if(!StringUtils.isEmpty(platUser.getScore())){
                platUser.setScoreState("已完成");
            }else{
                platUser.setScoreState("已开始");
            }
        }
        return list;
    }

    @Override
    public void removeLessonStudent(Long id) {
        platLessonStudentMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void addLessonStudent(Long userId, Long scheduleId, Long lessonId) {
        PlatLessonStudentExample example = new PlatLessonStudentExample();
        PlatLessonStudentExample.Criteria criteria = example.createCriteria();
        criteria.andUserIdEqualTo(userId);
        criteria.andScheduleIdEqualTo(scheduleId);
        criteria.andLessonIdEqualTo(lessonId);
        List<PlatLessonStudent> lessonStudentList = platLessonStudentMapper.selectByExample(example);

        PlatUser platUser = platUserMapper.selectByPrimaryKey(userId);
        if(platUser==null) {
            throw new BusinessException("学生id："+userId+"不存在!");
        }
        if(lessonStudentList.size()>0){
            throw new BusinessException("学生："+platUser.getNickName()+"已添加过了，请不要重复提交!");
        }else{
            PlatLessonStudent platLessonStudent = new PlatLessonStudent();
            platLessonStudent.setLessonId(lessonId);
            platLessonStudent.setUserId(userId);
            platLessonStudent.setState(0);
            platLessonStudent.setCreateTime(new Date());
            platLessonStudent.setScheduleId(scheduleId);
            platLessonStudent.setClassId(platUser.getClassId());
            platLessonStudent.setScore("");
            platLessonStudent.setCompleteTime("");
            platLessonStudentMapper.insert(platLessonStudent);
        }
    }

    @Override
    public StatisticalAnalysisVO dataStatistics(Long typeId,String startDate,String endDate,HttpServletRequest request) {
        //当前用户
        PlatUser loginUser = platUserService.getLoginUser(request);

        //排课信息
        List<Long> scheduleIdList = new ArrayList<>();
        List<PlatLessonSchedule> lessonScheduleList = null;
        if(true){
            PlatLessonScheduleExample example = new PlatLessonScheduleExample();
            PlatLessonScheduleExample.Criteria criteria = example.createCriteria();
            //教师只统计自己的课程
            if (loginUser.getRole() == ROLE_TEACHER) {
                criteria.andTeacherIdEqualTo(loginUser.getId());
            }
            lessonScheduleList = platLessonScheduleMapper.selectByExample(example);
            for(PlatLessonSchedule schedule:lessonScheduleList){
                scheduleIdList.add(schedule.getId());
            }
            if(scheduleIdList.size()==0){
                scheduleIdList.add(-1L);
            }
        }

        StatisticalAnalysisVO statisticalAnalysisVO = new StatisticalAnalysisVO();

        //参与实验班级
        List<PlatLessonStudent> lessonStudentList = null;
        if(true){
            PlatLessonStudentExample example = new PlatLessonStudentExample();
            PlatLessonStudentExample.Criteria criteria = example.createCriteria();
            criteria.andScheduleIdIn(scheduleIdList);
            lessonStudentList = platLessonStudentMapper.selectByExample(example);

            if(true){
                Set setClass = new HashSet();
                Set setUser = new HashSet();
                Set setLesson = new HashSet();
                int allNum = 0;
                int resultNum = 0;
                int jgNum = 0;

                //每个课程有多少个人
                Map<Long,Set> scoreDataNumMap = new LinkedHashMap<>();
                //每个课程下的总分
                Map<Long,Integer> scoreDataAllScoreMap = new LinkedHashMap<>();

                //每个课程有多少个人（完成的）
                Map<Long,Set> scoreTimeNumMap = new LinkedHashMap<>();
                //每个课程用时
                Map<Long,Long> scoreTimeMap = new LinkedHashMap<>();

                //各课程完成情况统计
                // 创建一个键为Long，值为Integer数组的Map
                Map<Long, Integer[]> longArrayMap = new LinkedHashMap<>();

                for(PlatLessonStudent platLessonStudent:lessonStudentList){
                    try {
                        if(!StringUtils.isEmpty(startDate)) {
                            if (platLessonStudent.getCreateTime().getTime() < new SimpleDateFormat("yyyy-MM-dd").parse(startDate).getTime()) {
                                continue;
                            }
                        }

                        if(!StringUtils.isEmpty(endDate)){
                            if (platLessonStudent.getCreateTime().getTime() > new SimpleDateFormat("yyyy-MM-dd").parse(endDate).getTime()) {
                                continue;
                            }
                        }
                    } catch (ParseException e) {
                        log.error("时间判断失败",e);
                    }

                    //各课程平均分分布=================开始
                    if(true){
                        Set setUserV = scoreDataNumMap.get(platLessonStudent.getLessonId())==null?new HashSet():scoreDataNumMap.get(platLessonStudent.getLessonId());
                        setUserV.add(platLessonStudent.getUserId());
                        scoreDataNumMap.put(platLessonStudent.getLessonId(),setUserV);
                    }

                    if(scoreDataAllScoreMap.get(platLessonStudent.getLessonId())==null){
                        scoreDataAllScoreMap.put(platLessonStudent.getLessonId(),0);
                    }
                    scoreDataAllScoreMap.put(platLessonStudent.getLessonId(),scoreDataAllScoreMap.get(platLessonStudent.getLessonId())+(StringUtils.isEmpty(platLessonStudent.getScore())?0:Integer.parseInt(platLessonStudent.getScore())));
                    //各课程平均分分布=================结束


                    //各课程平均用时分布=================开始
                    if(!StringUtils.isEmpty(platLessonStudent.getCompleteTime())&&platLessonStudent.getStartTime()!=null){
                        Set setUserV = scoreTimeNumMap.get(platLessonStudent.getLessonId())==null?new HashSet():scoreTimeNumMap.get(platLessonStudent.getLessonId());
                        setUserV.add(platLessonStudent.getUserId());
                        scoreTimeNumMap.put(platLessonStudent.getLessonId(),setUserV);

                        if(scoreTimeMap.get(platLessonStudent.getLessonId())==null){
                            scoreTimeMap.put(platLessonStudent.getLessonId(),0L);
                        }
                        try {
                            Date completeTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(platLessonStudent.getCompleteTime());
                            // 计算毫秒差
                            long diffInMillis = completeTime.getTime() - platLessonStudent.getStartTime().getTime();
                            // 转换为分钟
                            long diffInMinutes = diffInMillis / (60 * 1000);
                            scoreTimeMap.put(platLessonStudent.getLessonId(),scoreTimeMap.get(platLessonStudent.getLessonId())+diffInMinutes);
                        } catch (ParseException e) {
                            log.error("时间判断失败",e);
                        }

                    }
                    //各课程平均用时分布=================结束


                    //各课程完成情况统计=================开始
                    if(longArrayMap.get(platLessonStudent.getLessonId())==null){
                        longArrayMap.put(platLessonStudent.getLessonId(),new Integer[]{0,0,0});
                    }
                    Integer[] myData = longArrayMap.get(platLessonStudent.getLessonId());
                    if(!StringUtils.isEmpty(platLessonStudent.getCompleteTime())){
                        //已完成
                        longArrayMap.put(platLessonStudent.getLessonId(),new Integer[]{myData[0],myData[1],myData[2]+1});
                    }else if(platLessonStudent.getStartTime()!=null){
                        //未开始
                        longArrayMap.put(platLessonStudent.getLessonId(),new Integer[]{myData[0]+1,myData[1],myData[2]});
                    }else{
                        //进行中
                        longArrayMap.put(platLessonStudent.getLessonId(),new Integer[]{myData[0],myData[1]+1,myData[2]});
                    }
                    //各课程完成情况统计=================结束


                    setClass.add(platLessonStudent.getClassId());
                    setUser.add(platLessonStudent.getUserId());
                    setLesson.add(platLessonStudent.getLessonId());
                    allNum++;
                    if(!StringUtils.isEmpty(platLessonStudent.getScore())){
                        resultNum++;
                    }
                    if(!StringUtils.isEmpty(platLessonStudent.getScore())&&Integer.parseInt(platLessonStudent.getScore())>=60){
                        jgNum++;
                    }
                }

                //各课程平均分分布=================开始
                if(true){
                    List<String> listN = new ArrayList<>();
                    List<Integer> listV = new ArrayList<>();
                    for(Long key:scoreDataNumMap.keySet()){
                        PlatLesson lesson = platLessonMapper.selectByPrimaryKey(key);
                        if(lesson!=null){
                            listN.add(lesson.getName());
                            listV.add(scoreDataAllScoreMap.get(key)/scoreDataNumMap.get(key).size());
                        }
                    }
                    ScoreData scoreData = new ScoreData();
                    scoreData.setCategories(listN.toArray(new String[0]));
                    scoreData.setValues(listV.toArray(new Integer[0]));
                    statisticalAnalysisVO.setScoreData(scoreData);
                }
                //各课程平均分分布=================结束

                //各课程平均用时分布=================开始
                if(true){
                    List<String> listN = new ArrayList<>();
                    List<Integer> listV = new ArrayList<>();
                    for(Long key:scoreTimeMap.keySet()){
                        PlatLesson lesson = platLessonMapper.selectByPrimaryKey(key);
                        if(lesson!=null){
                            listN.add(lesson.getName());
                            listV.add(Integer.parseInt(String.valueOf(scoreTimeMap.get(key)/scoreTimeNumMap.get(key).size())));
                        }
                    }
                    ScoreData scoreDataTime = new ScoreData();
                    scoreDataTime.setCategories(listN.toArray(new String[0]));
                    scoreDataTime.setValues(listV.toArray(new Integer[0]));
                    statisticalAnalysisVO.setScoreDataTime(scoreDataTime);
                }
                //各课程平均用时分布=================结束

                //各课程完成情况统计=================开始
                if(true){
                    List<CompletionData> completionDataList = new ArrayList<>();
                    for(Long key:longArrayMap.keySet()){
                        PlatLesson lesson = platLessonMapper.selectByPrimaryKey(key);
                        if(lesson!=null){
                            CompletionData completionData = new CompletionData();
                            completionData.setName(lesson.getName());
                            completionData.setData(longArrayMap.get(key));
                            completionDataList.add(completionData);
                        }
                    }
                    statisticalAnalysisVO.setCompletionDataList(completionDataList);
                }
                //各课程完成情况统计=================结束

                //参与实验班级
                statisticalAnalysisVO.setClassNum(setClass.size());
                //参与实验总人数
                statisticalAnalysisVO.setUserNum(setUser.size());
                //实验课程总数
                statisticalAnalysisVO.setLessonNum(setLesson.size());
                //实验完成率 计算百分比（保留2位小数）
                statisticalAnalysisVO.setResultBfb(allNum==0?"0%":String.format("%.2f%%", (double) resultNum / allNum * 100));
                //实验及格率 计算百分比（保留2位小数）
                statisticalAnalysisVO.setJgBfb(allNum==0?"0%":String.format("%.2f%%", (double) jgNum / allNum * 100));
            }
        }
        return statisticalAnalysisVO;
    }

    @Override
    public void savrInitAnsTime(Long lessonId, Long platLessonStudentId, HttpServletRequest request) {
        PlatUser loginUser = platUserService.getLoginUser(request);

        PlatLessonStudentExample example = new PlatLessonStudentExample();
        PlatLessonStudentExample.Criteria criteria = example.createCriteria();
        criteria.andLessonIdEqualTo(lessonId);
        criteria.andIdEqualTo(platLessonStudentId);
        criteria.andUserIdEqualTo(loginUser.getId());
        List<PlatLessonStudent> lessonStudentList = platLessonStudentMapper.selectByExample(example);
        for(PlatLessonStudent platLessonStudent:lessonStudentList){
            platLessonStudent.setStartTime(new Date());
            platLessonStudentMapper.updateByPrimaryKey(platLessonStudent);
        }
    }

    @Override
    public PlatLessonType lessonType(Long id) {
        return platLessonTypeMapper.selectByPrimaryKey(id);
    }

    @Override
    public void copy(Long lessonId) {
        PlatLesson platLesson = platLessonMapper.selectByPrimaryKey(lessonId);
        if(platLesson == null){
            throw new BusinessException("课程不存在!");
        }
        PlatLesson platLessonCopy = new PlatLesson();
        BeanUtils.copyProperties(platLesson, platLessonCopy);
        platLessonCopy.setId(null);
        platLessonCopy.setName(platLesson.getName()+"_" + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()));// 获取当前时间
        platLessonCopy.setCreateTime(new Date());
        platLessonCopy.setUpdateTime(new Date());
        platLessonMapper.insert(platLessonCopy);

        //子课程列表
        PlatLessonSonExample platLessonSonExample = new PlatLessonSonExample();
        PlatLessonSonExample.Criteria platLessonSonExampleCriteria = platLessonSonExample.createCriteria();
        platLessonSonExampleCriteria.andLessonIdEqualTo(lessonId);
        List<PlatLessonSon> list = platLessonSonMapper.selectByExample(platLessonSonExample);
        for(PlatLessonSon platLessonSon:list){
            PlatLessonSon platLessonSonCopy = new PlatLessonSon();
            BeanUtils.copyProperties(platLessonSon, platLessonSonCopy);
            platLessonSonCopy.setId(null);
            platLessonSonCopy.setCreateTime(new Date());
            platLessonSonCopy.setUpdateTime(new Date());
            platLessonSonCopy.setLessonId(platLessonCopy.getId());
            platLessonSonCopy.setOldId(platLessonSon.getId());
            platLessonSonMapper.insert(platLessonSonCopy);
        }
    }
}
